import{U as M,z as C,ap as h,aq as x,m as y,ar as w,as as P,at as T,au as D,C as p,a6 as R,a as N,I as g,R as F,p as E,n as A,B as I,a3 as U,t as O,ao as m}from"./OrbitControls-2d7cb36a.js";import{M as z,R as B}from"./index-8df8af93.js";import{D as G}from"./index-4ec0cc76.js";import{g as v}from"./index-4db78ffb.js";import{P as b,F as S,R as H,S as L,E as k}from"./RenderPass-0b2ff0ec.js";import{U as j}from"./UnrealBloomPass-f6b4678f.js";import{_ as W}from"./_plugin-vue_export-helper-c27b6911.js";import{g as Q,h as J,o as V,c as X,b as u,u as f,p as Y,i as $}from"./index-cb7b4472.js";import"./lil-gui.module.min-f00c3c61.js";const q="/threejs-3d/assets/SuzanneModel-b2e855de.glb",K="/threejs-3d/assets/HuoJianModel-8b394a47.glb",Z="/threejs-3d/assets/CameraModel-cd53b5eb.glb",ee="/threejs-3d/assets/gradient-ad0fa16e.png",te={name:"FilmShader",uniforms:{tDiffuse:{value:null},time:{value:0},nIntensity:{value:.5},sIntensity:{value:.05},sCount:{value:4096},grayscale:{value:1}},vertexShader:`

		varying vec2 vUv;

		void main() {

			vUv = uv;
			gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );

		}`,fragmentShader:`

		#include <common>

		// control parameter
		uniform float time;

		uniform bool grayscale;

		// noise effect intensity value (0 = no effect, 1 = full effect)
		uniform float nIntensity;

		// scanlines effect intensity value (0 = no effect, 1 = full effect)
		uniform float sIntensity;

		// scanlines effect count value (0 = no effect, 4096 = full effect)
		uniform float sCount;

		uniform sampler2D tDiffuse;

		varying vec2 vUv;

		void main() {

		// sample the source
			vec4 cTextureScreen = texture2D( tDiffuse, vUv );

		// make some noise
			float dx = rand( vUv + time );

		// add noise
			vec3 cResult = cTextureScreen.rgb + cTextureScreen.rgb * clamp( 0.1 + dx, 0.0, 1.0 );

		// get us a sine and cosine
			vec2 sc = vec2( sin( vUv.y * sCount ), cos( vUv.y * sCount ) );

		// add scanlines
			cResult += cTextureScreen.rgb * vec3( sc.x, sc.y, sc.x ) * sIntensity;

		// interpolate between source and result by intensity
			cResult = cTextureScreen.rgb + clamp( nIntensity, 0.0,1.0 ) * ( cResult - cTextureScreen.rgb );

		// convert to grayscale if desired
			if( grayscale ) {

				cResult = vec3( cResult.r * 0.3 + cResult.g * 0.59 + cResult.b * 0.11 );

			}

			gl_FragColor =  vec4( cResult, cTextureScreen.a );

		}`};class se extends b{constructor(e,s,t,i){super();const o=te;this.uniforms=M.clone(o.uniforms),this.material=new C({name:o.name,uniforms:this.uniforms,vertexShader:o.vertexShader,fragmentShader:o.fragmentShader}),i!==void 0&&(this.uniforms.grayscale.value=i),e!==void 0&&(this.uniforms.nIntensity.value=e),s!==void 0&&(this.uniforms.sIntensity.value=s),t!==void 0&&(this.uniforms.sCount.value=t),this.fsQuad=new S(this.material)}render(e,s,t,i){this.uniforms.tDiffuse.value=t.texture,this.uniforms.time.value+=i,this.renderToScreen?(e.setRenderTarget(null),this.fsQuad.render(e)):(e.setRenderTarget(s),this.clear&&e.clear(),this.fsQuad.render(e))}dispose(){this.material.dispose(),this.fsQuad.dispose()}}const ie={uniforms:{tDiffuse:{value:null},screenWidth:{value:1024},screenHeight:{value:1024},sampleDistance:{value:.94},waveFactor:{value:.00125}},vertexShader:`

		varying vec2 vUv;

		void main() {

			vUv = uv;
			gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );

		}`,fragmentShader:`

		uniform float screenWidth;
		uniform float screenHeight;
		uniform float sampleDistance;
		uniform float waveFactor;

		uniform sampler2D tDiffuse;

		varying vec2 vUv;

		void main() {

			vec4 color, org, tmp, add;
			float sample_dist, f;
			vec2 vin;
			vec2 uv = vUv;

			add = color = org = texture2D( tDiffuse, uv );

			vin = ( uv - vec2( 0.5 ) ) * vec2( 1.4 );
			sample_dist = dot( vin, vin ) * 2.0;

			f = ( waveFactor * 100.0 + sample_dist ) * sampleDistance * 4.0;

			vec2 sampleSize = vec2(  1.0 / screenWidth, 1.0 / screenHeight ) * vec2( f );

			add += tmp = texture2D( tDiffuse, uv + vec2( 0.111964, 0.993712 ) * sampleSize );
			if( tmp.b < color.b ) color = tmp;

			add += tmp = texture2D( tDiffuse, uv + vec2( 0.846724, 0.532032 ) * sampleSize );
			if( tmp.b < color.b ) color = tmp;

			add += tmp = texture2D( tDiffuse, uv + vec2( 0.943883, -0.330279 ) * sampleSize );
			if( tmp.b < color.b ) color = tmp;

			add += tmp = texture2D( tDiffuse, uv + vec2( 0.330279, -0.943883 ) * sampleSize );
			if( tmp.b < color.b ) color = tmp;

			add += tmp = texture2D( tDiffuse, uv + vec2( -0.532032, -0.846724 ) * sampleSize );
			if( tmp.b < color.b ) color = tmp;

			add += tmp = texture2D( tDiffuse, uv + vec2( -0.993712, -0.111964 ) * sampleSize );
			if( tmp.b < color.b ) color = tmp;

			add += tmp = texture2D( tDiffuse, uv + vec2( -0.707107, 0.707107 ) * sampleSize );
			if( tmp.b < color.b ) color = tmp;

			color = color * vec4( 2.0 ) - ( add / vec4( 8.0 ) );
			color = color + ( add / vec4( 8.0 ) - color ) * ( vec4( 1.0 ) - vec4( sample_dist * 0.5 ) );

			gl_FragColor = vec4( color.rgb * color.rgb * vec3( 0.95 ) + color.rgb, 1.0 );

		}`},oe={uniforms:{tDiffuse:{value:null},toneMappingExposure:{value:1}},vertexShader:`
		precision highp float;

		uniform mat4 modelViewMatrix;
		uniform mat4 projectionMatrix;

		attribute vec3 position;
		attribute vec2 uv;

		varying vec2 vUv;

		void main() {

			vUv = uv;
			gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );

		}`,fragmentShader:`
	
		precision highp float;

		uniform sampler2D tDiffuse;

		`+h.tonemapping_pars_fragment+h.colorspace_pars_fragment+`

		varying vec2 vUv;

		void main() {

			gl_FragColor = texture2D( tDiffuse, vUv );

			// tone mapping

			#ifdef LINEAR_TONE_MAPPING

				gl_FragColor.rgb = LinearToneMapping( gl_FragColor.rgb );

			#elif defined( REINHARD_TONE_MAPPING )

				gl_FragColor.rgb = ReinhardToneMapping( gl_FragColor.rgb );

			#elif defined( CINEON_TONE_MAPPING )

				gl_FragColor.rgb = OptimizedCineonToneMapping( gl_FragColor.rgb );

			#elif defined( ACES_FILMIC_TONE_MAPPING )

				gl_FragColor.rgb = ACESFilmicToneMapping( gl_FragColor.rgb );

			#endif

			// color space

			#ifdef SRGB_COLOR_SPACE

				gl_FragColor = LinearTosRGB( gl_FragColor );

			#endif

		}`};class ae extends b{constructor(){super();const e=oe;this.uniforms=M.clone(e.uniforms),this.material=new x({uniforms:this.uniforms,vertexShader:e.vertexShader,fragmentShader:e.fragmentShader}),this.fsQuad=new S(this.material),this._outputColorSpace=null,this._toneMapping=null}render(e,s,t){this.uniforms.tDiffuse.value=t.texture,this.uniforms.toneMappingExposure.value=e.toneMappingExposure,(this._outputColorSpace!==e.outputColorSpace||this._toneMapping!==e.toneMapping)&&(this._outputColorSpace=e.outputColorSpace,this._toneMapping=e.toneMapping,this.material.defines={},this._outputColorSpace==y&&(this.material.defines.SRGB_COLOR_SPACE=""),this._toneMapping===w?this.material.defines.LINEAR_TONE_MAPPING="":this._toneMapping===P?this.material.defines.REINHARD_TONE_MAPPING="":this._toneMapping===T?this.material.defines.CINEON_TONE_MAPPING="":this._toneMapping===D&&(this.material.defines.ACES_FILMIC_TONE_MAPPING=""),this.material.needsUpdate=!0),this.renderToScreen===!0?(e.setRenderTarget(null),this.fsQuad.render(e)):(e.setRenderTarget(s),this.clear&&e.clear(e.autoClearColor,e.autoClearDepth,e.autoClearStencil),this.fsQuad.render(e))}dispose(){this.material.dispose(),this.fsQuad.dispose()}}class ne extends z{constructor(e){super(e),this.scene.background=new p(855073),this.scene.fog=new R(855073,5e-4),this.renderer.instance.setClearColor(855073),this.camera.instance.fov=75,this.camera.instance.near=1,this.camera.instance.far=5e4,this.camera.instance.position.set(0,0,1e3),this.camera.controls.enabled=!1,this.mouseX=0,this.mouseY=0,this.initRender(),this.initSetting(),this.initPost(),this.initAssets(()=>{this.initModel(),document.body.addEventListener("pointermove",s=>{this.onPointerMove(s)})})}initPost(){const e=new H(this.scene,this.camera.instance),s=new se(.35,.025,686,!1);s.renderToScreen=!0,s.enabled=!1;const t=new L(ie);t.uniforms.screenWidth.value=window.offsetWidth,t.uniforms.screenHeight.value=window.offsetHeight,t.uniforms.sampleDistance.value=.5,t.renderToScreen=!0;const i={strength:.75,radius:.42,threshold:.2,exposure:1,sampleDistance:5},o=new j(new N(window.innerWidth,window.innerHeight),i.strength,i.radius,i.threshold),r=new ae;if(r.renderToScreen=!0,this.composer=new k(this.renderer.instance),this.composer.addPass(e),this.composer.addPass(o),this.composer.addPass(s),this.composer.addPass(t),this.composer.addPass(r),this.renderer.postprocessing=!0,this.renderer.composer=this.composer,this.debug.active){const a=this.debug.instance.addFolder("post");a.add(i,"strength",0,3,.01).onChange(n=>{o.strength=Number(n)}),a.add(i,"radius",0,1,.01).onChange(n=>{o.radius=Number(n)}),a.add(i,"threshold",0,1,.01).onChange(n=>{o.threshold=Number(n)}),a.add(i,"exposure",.1,2,.01).onChange(n=>{this.renderer.instance.toneMappingExposure=Math.pow(n,4)})}}initRender(){this.renderer.instance.outputColorSpace=g}initSetting(){this.debug=new G(!1)}initAssets(e){let s=new B({});s.loadAll([{type:"GLTF",name:"CameraModel",path:Z},{type:"GLTF",name:"SuzanneModel",path:q},{type:"GLTF",name:"HuoJianModel",path:K},{type:"Texture",name:"particleTexture",path:ee}]),s.on("onLoad",()=>{e&&e()}),this.assets=s}initModel(){let e=this.assets.getResource("CameraModel").scene.getObjectByName("CameraModel"),s=this.assets.getResource("SuzanneModel").scene.getObjectByName("SuzanneModel"),t=this.assets.getResource("HuoJianModel").scene.getObjectByName("HuoJianModel");this.model={CameraModel:e,SuzanneModel:s,HuoJianModel:t},this.particleNumber=Math.max(e.geometry.getAttribute("position").count,s.geometry.getAttribute("position").count,t.geometry.getAttribute("position").count),this.currentCompleteNumber=0,this.currentModel=null,this.clickEnable=!1;let[i,o]=this.createParticle();v.to(i.rotation,{y:2*Math.PI,duration:3,ease:"none",onComplete:()=>{this.clickEnable=!0,this.toggleModel()}})}toggleModel(e="HuoJianModel"){if(this.currentModel===e||!this.clickEnable)return!1;this.currentModel=e,this.clickEnable=!1,this.currentCompleteNumber=0;let s=this.points,t=this.position,i=this.model,o=s.geometry.getAttribute("position"),r=i[e].geometry.getAttribute("position");for(let a=0;a<o.count;a++){const n=a%r.count;v.to(t,{[a*3]:r.array[n*3],[a*3+1]:r.array[n*3+1],[a*3+2]:r.array[n*3+2],duration:1*Math.random(),delay:Math.random()*1,ease:"power3.out",onUpdate:()=>{o.needsUpdate=!0},onComplete:()=>{this.currentCompleteNumber++,this.currentCompleteNumber>=this.particleNumber&&(this.clickEnable=!0)}})}}createParticle(){let e=this.assets.getResource("particleTexture");e.colorSpace=g,e.wrapS=e.wrapT=F;const s=new E({color:new p("#e5eeff"),map:e,alphaMap:e,sizeAttenuation:!0,transparent:!0,depthTest:!1,size:10,blending:A}),t=this.particleNumber,i=new I,o=new Float32Array(t*3);for(let c=0;c<t;c++){var r=m.randFloatSpread(1e3),a=m.randFloatSpread(1e3),n=m.randFloatSpread(12e3);o[c]=r,o[c+1]=a,o[c+2]=n}i.setAttribute("position",new U(o,3));const d=new O(i,s);return this.scene.add(d),this.position=o,this.points=d,this.debug.active&&this.debug.instance.addFolder("point material").addColor(s,"color").onChange(_=>{s.color=new p(_)}),[d,o]}onPointerMove(e){if(e.isPrimary===!1)return!1;this.mouseX=e.clientX-window.innerWidth/2,this.mouseY=e.clientY-window.innerHeight/2}update(){super.update(),this.stats&&this.stats.update(),this.camera.instance.position.x-=(this.mouseX+this.camera.instance.position.x*2)*.05,this.camera.instance.position.y-=(-this.mouseY+this.camera.instance.position.y)*.001,this.camera.instance.lookAt(this.scene.position)}destroy(){super.destroy(),this.debug.destroy(),document.body.removeChild(this.stats.dom)}}const re=l=>(Y("data-v-2452fa63"),l=l(),$(),l),le={class:"particle-wrap"},ce=re(()=>u("canvas",{id:"canvas"},null,-1)),ue={class:"btn-group"},de={__name:"particle01-model",setup(l){let e=null;return Q(()=>{e=new ne(document.getElementById("canvas"))}),J(()=>{e&&e.destroy()}),(s,t)=>(V(),X("div",le,[ce,u("div",ue,[u("div",{class:"btn",onClick:t[0]||(t[0]=i=>f(e).toggleModel("HuoJianModel"))},"火箭"),u("div",{class:"btn",onClick:t[1]||(t[1]=i=>f(e).toggleModel("CameraModel"))},"摄像机"),u("div",{class:"btn",onClick:t[2]||(t[2]=i=>f(e).toggleModel("SuzanneModel"))},"猴头")])]))}},_e=W(de,[["__scopeId","data-v-2452fa63"]]);export{_e as default};
